
Public Class XRayResultHistory

    Protected _year As String
    Protected _police As New Police()
    Protected _x_ray_result As New XRayResult()
    Protected _police_full_name As String
    Protected _police_age As Integer
    Protected _Data As ArrayList
    Protected _DataCurrent As Integer

    Public Property police() As Police
        Get
            Return _police
        End Get
        Set(ByVal value As Police)
            _police = value
        End Set
    End Property

    Public Property police_full_name() As String
        Get
            Return _police_full_name
        End Get
        Set(ByVal value As String)
            _police_full_name = value
        End Set
    End Property

    Public Property police_age() As Integer
        Get
            Return _police_age
        End Get
        Set(ByVal value As Integer)
            _police_age = value
        End Set
    End Property

    Public Property year() As String
        Get
            Return _year
        End Get
        Set(ByVal value As String)
            _year = value
        End Set
    End Property

    Public Property x_ray_result() As XRayResult
        Get
            Return _x_ray_result
        End Get
        Set(ByVal value As XRayResult)
            _x_ray_result = value
        End Set
    End Property

    Public Function getPoliceXRayInOrganizationAll(ByVal inOrganizationID As String, ByVal inYear As String) As DataSet
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_PoliceXRayResultHistory"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inOrganizationID", inOrganizationID)
        objCmd.Parameters.Add(objParam)

        objParam = New MySql.Data.MySqlClient.MySqlParameter("inYear", inYear)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "PoliceXRay")

        Return objDs
    End Function

    Public Function getsPoliceXRayInOrganizationAll(ByVal inOrganizationID As String, ByVal inYear As String) As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_PoliceXRayResultHistory"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inOrganizationID", inOrganizationID)
        objCmd.Parameters.Add(objParam)

        objParam = New MySql.Data.MySqlClient.MySqlParameter("inYear", inYear)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "PoliceXRay")

        For Each objDr As System.Data.DataRow In objDs.Tables("PoliceXRay").Rows
            Dim obj As XRayResultHistory = New XRayResultHistory
            obj.police.citizen_id = objDr.Item("citizen_id")
            obj.police_full_name = objDr.Item("full_name")
            obj.police_age = Utilities.ClearDBNullToMinValue(objDr.Item("age"), TypeCode.Int32)
            obj.x_ray_result.x_ray_result_id = Utilities.ClearDBNullToMinValue(objDr.Item("x_ray_result_id"), TypeCode.String)

            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Public Sub LoadPoliceBMIInOrganizationAll(ByVal inOrganizationID As String, ByVal inYear As String)
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getsPoliceXRayInOrganizationAll(inOrganizationID, inYear)
    End Sub

    Public Function NextRecord() As Boolean
        If ((Not _Data Is Nothing) AndAlso (((Not _Data Is Nothing) AndAlso _
            (_DataCurrent < _Data.Count And _Data.Count > 0)))) Then
            _police.citizen_id = _Data(_DataCurrent).police.citizen_id
            _police_full_name = _Data(_DataCurrent).police_full_name
            _police_age = _Data(_DataCurrent).police_age
            _x_ray_result.x_ray_result_id = _Data(_DataCurrent).x_ray_result.x_ray_result_id
            _DataCurrent += 1
            Return True
        End If
        Return False
    End Function

    Public Sub deletePoliceXRayResultHistory(ByVal inPoliceXRayResultHistory As XRayResultHistory)
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_DELETE_PoliceXRayResultHistory"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inCitizenID", _
                Utilities.SendToDatabase(inPoliceXRayResultHistory.police.citizen_id))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inYear", _
                Utilities.SendToDatabase(inPoliceXRayResultHistory.year))
            objCmd.Parameters.Add(objParam)


            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Public Function insertPoliceXRayResultHistory(ByVal inPoliceXRayResultHistory As XRayResultHistory) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_PoliceXRayResultHistory"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inCitizenID", _
                Utilities.SendToDatabase(inPoliceXRayResultHistory.police.citizen_id))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inYear", _
                Utilities.SendToDatabase(inPoliceXRayResultHistory.year))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inOrganizationID", _
                Utilities.SendToDatabase(inPoliceXRayResultHistory.police.organization.organization_id))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inOrganizationNameTha", _
                 Utilities.SendToDatabase(inPoliceXRayResultHistory.police.organization.organization_name_tha))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inXRayResultID", _
                Utilities.SendToDatabase(inPoliceXRayResultHistory.x_ray_result.x_ray_result_id))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inCreateUser", _
                Utilities.SendToDatabase(inPoliceXRayResultHistory.police.create_user))
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Sub insertXRaySummaryReportValue(ByVal inYear As String, ByVal inOrganizationID As String)
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_XRaySummaryReport"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inYear", inYear)
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inOrganizationID", inOrganizationID)
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Public Sub insertXRayAbnormalSummaryReportValue(ByVal inYear As String, ByVal inOrganizationID As String)
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_XRayAbnormalSummaryReport"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inYear", inYear)
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inOrganizationID", inOrganizationID)
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

        Catch ex As Exception
            Throw ex
        End Try
    End Sub

End Class
